package com.example.tms.mapper;

import com.example.tms.bean.CstmrInfo;
import com.example.tms.bean.OrderMgmt;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 客户信息
 */
@Repository
public interface CstmrMapper extends JpaRepository<CstmrInfo,String>, JpaSpecificationExecutor<CstmrInfo> {

    List<CstmrInfo> findBySfczOrderByLasttimeAsc(Boolean sfcz);

    //查询客户信息（客户id）
    @Query(value = "select * from cstmr_info where khid = ?1 and sfcz = true ", nativeQuery = true)
    CstmrInfo findByKhid(String khid);

    //删除客户信息（假删除 客户id）
    @Query(value = "update cstmr_info set sfcz = false where khid = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void DeleteByKhid(String khid);

    //更新客户资料（客户id）
    @Query(value = "update cstmr_info set wjsc = ?2 where khid = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void updateWjsc(String khid, String wjsc);
    CstmrInfo findByKhidAndSfcz(String khid, boolean sfcz);

}
